#!/usr/bin/env python
# -*- conding: utf-8 -*-

"""
@Time     : 2024/8/15 21:52
@Author   : liujingmao
@File     : google_serper_tool.py
"""
import dotenv
from langchain_community.tools import GoogleSerperRun
from langchain_community.utilities import GoogleSerperAPIWrapper
from pydantic.v1 import BaseModel, Field


class GoogleSerperArgsSchema(BaseModel):
    query: str = Field(description="执行谷歌搜索的查询语句")


dotenv.load_dotenv()
google_serper = GoogleSerperRun(
    name="googleserper",
    description=(
        "一个低成本的谷歌搜索API。"
        "当你需要回答有关时事的问题时，可以调用该工具。"
        "该工具的输入是搜索查询语句"
    ),
    args=GoogleSerperArgsSchema,
    api_wrapper=GoogleSerperAPIWrapper(),
)

print(google_serper.invoke("有关中国男篮U18的最新消息"))
